package com.ccys.common.constants;

import com.ccys.common.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * 三方参数 读取当前包下的oss.properties
 * <p>
 * 当本地启动时，因为不存在file路径，所以会加载classpath；
 * 当jar启动时，若file路径不存在，会加载classpath；反之会加载file路径同时覆盖classpath路径下的内容；
 * ignoreResourceNotFound = true 一定要加上，否则找不到会报错。加上之后会忽略找不到的配置文件。
 *
 * @author Administrator
 */
@Component("AppSettingsConstants")
@PropertySource(value = {"classpath:config/appSettings.properties", "file:./config/appSettings.properties", "file:./../config/appSettings.properties"}, ignoreResourceNotFound = true, encoding = "utf-8")
@Slf4j
public class AppSettingsConstants {
    public static String sendSms;
    public static int smsLimitCount;
    public static int smsBlockDurationInSeconds;

    @Value("${sendSms}")
    public void setSendSms(String sendSms) {
        if (StringUtil.isNotBlank(sendSms)) {
            sendSms = sendSms.trim();
        }
        AppSettingsConstants.sendSms = sendSms;
    }
    @Value("${smsLimitCount}")
    public void setSmsLimitCount(int smsLimitCount) {
        AppSettingsConstants.smsLimitCount = smsLimitCount;
    }
    @Value("${smsBlockDurationInSeconds}")
    public void setSmsBlockDurationInSeconds(int smsBlockDurationInSeconds) {
        AppSettingsConstants.smsBlockDurationInSeconds = smsBlockDurationInSeconds;
    }

}
